<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okText="tab==1?'下一步':'确定创建'"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    :cancelText="tab==1?'关闭':'上一步'">
    <qy-marketing-form ref="realForm" @ok="submitCallback" @switchTab="switchTab" :disabled="disableSubmit"></qy-marketing-form>

  </j-modal>
</template>

<script>

  import QyMarketingForm from './QyMarketingForm'
  export default {
    components: {
      QyMarketingForm
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        tab:1
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        if(this.tab==1){
          this.$refs.realForm.toNext();
        }else{
          this.$refs.realForm.submitForm();
        }

      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
        this.tab = 1;
      },
      handleCancel (e) {
        if (e.target.className == "ant-btn") {
          if(this.tab==1){
            this.close();
          }else{
            this.tab=1;
            this.$refs.realForm.toTab1();
          }
        }else{
          this.close();
          this.tab=1;
          this.$refs.realForm.toTab1();
        }

      },switchTab(tab){
        this.tab=tab;
      }
    }
  }
</script>